<template>
	<view>
		<view class="tabs-view">
			<u-tabs :list="list1" lineColor="#008F3D" :activeStyle="{color:'#008F3D'}"
			itemStyle="width:100px; height: 50px;" @click="getTabs"></u-tabs>
		</view>
		<view style="padding: 30rpx;">
			<view class="coupon-view mb-3" v-for="(item,index) in list" :key="index"
			@click="choose(item)">
				<view class="coupon-view-left">
				   <text v-if="is_type !=1" style="font-size: 30px;color: #999999;margin-right: 10rpx;">{{item.money}}</text>
				   <text v-else style="font-size: 30px;color: #F26D72;margin-right: 10rpx;">{{item.money}}</text>
				   <text style="font-size: 13px;color: #333333;">元</text>
				</view>
				<view class="flex-1 ml-3">
					<view style="font-size: 15px;margin-bottom: 10rpx;">{{item.title}}</view>
					<view style="font-size: 13px;color: #999999;margin-bottom: 10rpx;">
					   满{{item.max_money}}元减{{item.money}}元
					</view>
					<view style="font-size: 13px;color: #999999;margin-bottom: 10rpx;">{{item.endtime}}</view>
					<!-- <view style="font-size: 13px;color: #999999;">全平台可用</view> -->
				</view>
				<view class="coupon-view-btn" v-if="isChoose=='创建订单页面' && is_type ==1">去使用</view>
				<!-- <view class="coupon-view-btn" v-if="is_type==1">待使用</view> -->
				<view class="coupon-view-btn1" v-if="is_type==3">已使用</view>
				<view class="coupon-view-btn1" v-if="is_type==2">已过期</view>
			</view>
			
			
			<view v-if="list.length == 0" style="margin-top: 150rpx;flex-direction: column;" class="flex align-center justify-center">
				<!-- <u-empty
				        mode="car"
				        icon="http://cdn.uviewui.com/uview/empty/car.png"
				>
				</u-empty> -->
				<u-empty
				        mode="coupon"
				        icon="http://cdn.uviewui.com/uview/empty/coupon.png"
				>
				</u-empty>
				<view class="coupon-btn" v-if="is_type == 1" @click="goToUrl('/pages/index/coupon-center')">前往领券中心领取</view>
			</view>
			<view style="padding-bottom: 100rpx;">
				<u-loadmore v-if="loading" status="loading" />
				<u-loadmore v-if="isLastPage" status="nomore" />
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				limit:10,
				list:[],
				isLastPage: false,
				loading: false,
				list1:[
					{
						name: '待使用',
					},
					{
						name: '已使用',
					},
					{
						name: '已过期'
					}
				],
				is_type:1 ,//1:未使用2:已过期3:已使用。
				isChoose:''
			}
		},
		onLoad(e) {
			this.isChoose = e.isChoose
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.getCoupopAll()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.getCoupopAll().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.getCoupopAll();
			} else {
				this.isLastPage = true
			}
		},
		methods:{
			// 订单页面选择优惠卷
			choose(item){
				console.log('item',item)
				if(this.isChoose == '创建订单页面'){
					// 通知订单提交页修改收货地址
					uni.$emit('chooseCoupon',item)
					// 关闭当前页面
					uni.navigateBack({
						delta: 1
					});
				}
				
			},
			// 选择优惠卷状态
			getTabs(e){
				console.log(e)
				if(e.name == '已使用'){
					this.is_type = 3
				}else if(e.name == '已过期'){
					this.is_type = 2
				}else{
					this.is_type = 1
				}
				
				this.page = 1
				this.limit = 10
				this.list = []
				this.getCoupopAll()
			},
			goToUrl(url){
				uni.navigateTo({
					url:url
				})
			},
			getCoupopAll(){
				let parmar = {
					page: this.page,
					limit: this.limit,
					is_type:this.is_type
				}
				this.$api.couponAll(parmar).then(res => {
					if (res.code === 1) {
						 this.list = [...this.list, ...res.data.data]
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.coupon-btn{
		width: 400rpx;
		height: 80rpx;
		font-weight: 400;
		font-size: 28rpx;
		color: #008F3D;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		border: 1rpx solid #008F3D;
		margin-top: 20rpx;
	}
	.tabs-view {
		padding: 30rpx;
		background-color: #ffffff;
	}

	.coupon-view {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 30rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
	}
	
	.coupon-view-btn1 {
		width: 128rpx;
		height: 50rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #999999;
		text-align: center;
		line-height: 50rpx;
		border-radius: 25rpx;
		border: 1rpx solid #999999;
		background-color: #f5f5f5;
	}

	.coupon-view-btn {
		width: 128rpx;
		height: 50rpx;
		font-weight: 400;
		font-size: 26rpx;
		color: #008F3D;
		text-align: center;
		line-height: 50rpx;
		border-radius: 25rpx;
		border: 1rpx solid #008F3D;
	}
</style>